package ai.people.platform.archives.controller;

import ai.people.netmon.framework.domain.archives.entity.ArchivesUserAssociation;
import ai.people.netmon.framework.domain.archives.vo.ShareUserVO;
import ai.people.netmon.framework.model.response.ListResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.platform.archives.service.ArchivesShareUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 分享用户接口
 *
 * @author yuanqinglong
 * @date 2022/3/31 10:45
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/user")
public class ArchivesShareUserController {

    /**
     * 共享用户服务impl
     */
    private final ArchivesShareUserService shareUserServiceImpl;


    /**
     * 分享用户列表
     *
     * @param archiveId 档案id
     * @return {@link Result}<{@link ListResponse}<{@link ShareUserVO}>>
     */
    @GetMapping("/listShareUsers")
    public Result<ListResponse<ShareUserVO>> listShareUsers(@NotNull(message = "档案id为空") @RequestParam("archiveId") Long archiveId){
        return ResultUtil.success(shareUserServiceImpl.shareUserList(archiveId));
    }


    /**
     * 分享档案
     *
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("shareArchives")
    public Result<?> shareArchives(@Validated @RequestBody ArchivesUserAssociation archivesUserAssociation){
        shareUserServiceImpl.shareArchives(archivesUserAssociation);
        return ResultUtil.success();
    }


}
